import { rest } from 'msw';

export const handlers = [
    rest.post('/api/login', async(req, res, ctx) => {
        const { username, password } = await req.json();
        const validUsers = [
            { username: '13556488527', password: '741852963' },
            { username: 'test614', password: '123456789' }
        ];
        if (validUsers.some(u => u.username === username && u.password === password)) {
            return res(
                ctx.status(200),
                ctx.json({ code:200,
                    msg:"Login successful",
                    data:{
                        token:"fake-token-12345",
                        userInfo:{ name:"John Doe", role:"admin"}
                    }
                })
            );
        } else {
            return res(
                ctx.status(401),
                ctx.json({   
                    code:401,
                    msg:"账号或密码错误，请重试！",})
            );
        }
    })
]